<template>
  <div class="list">
    <!-- 列表标题 -->
        <div class="title">猜你喜欢</div>
        <!-- 列表综合排序按钮 -->
        <div class="list_btn">
            <div @click="listClickBtn(index)" :class="{btnAcivt:listBtnIndex==index}" v-for="(item,index) in listBtnArr" :key="index">{{item}}</div>
        </div>
        <!-- 列表综合排序下面的列表 -->
        <div class="list_content">
            <div  v-for="(item,index) in listContentArr" :key="index">{{item}}</div>
        </div>
        <!-- 列表综合排序商品信息列表 -->
        <div class="list_good" v-for="(item,index) in listgoodArrange" :key="index">
            <!-- 商品图标 -->
            <div class="good_img">
                <img :src="item.pic" alt="">
            </div>
            <!-- 商品信息 -->
            <div class="good_message">
                <div class="good">
                    <!-- 商品名称 -->
                    <div class="good_name">{{item.name}}</div>
                    <!-- 商品评分 -->
                    <span class="evaluation">⭐{{item.pf}}</span>
                    <span>月销{{item.yx}}</span><br>
                    <span>起送￥{{item.price}}</span>
                    <span>远距离配送￥{{item.ps}}</span>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <span>{{item.minute}}分钟</span>
                    <span>{{item.distance}}km</span>
                </div>
                <div class="manjian">
                    <div v-for="(item,index) in item.discounts" :key="index">{{item}}</div>
                </div>
            </div>
        </div>

  </div>
</template>

<script>
let pic="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fc-ssl.duitang.com%2Fuploads%2Fblog%2F202107%2F09%2F20210709142454_dc8dc.thumb.1000_0.jpeg&refer=http%3A%2F%2Fc-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1668252949&t=32888dccdc1c06ce37fd459b51d267a7"
export default {
    data(){
        return {
            // 用来存储列表变量
            listBtnIndex:0,
            // 列表按钮信息
            listBtnArr:['综合排序','距离最近','销量最高','筛选'],
            // 列表按钮下面的列表信息
            listContentArr:['年货节热卖','津贴联盟','海量优惠','品质联盟'],
            // 商家信息
            listgoodArrange:[
                {pic,name:"金百万烤鸭",pf:4.3,yx:1832,price:20,ps:3,minute:47,distance:3.9,discounts:['35减12','70减35','100减45','160减60']},
                {pic,name:"稻香金源饺子馆",pf:4.4,yx:230,price:20,ps:3.5,minute:44,distance:2.5,discounts:['40减5','89减8','100减10','支持自取']},
            ],
        }
    },
    methods:{
        // 综合排序方法
        listClickBtn(index){
            this.listBtnIndex=index;
            if(index==1){
                this.listgoodArrange.sort((a,b)=>{
                    return a.distance -b.distance;
                })
            }else if(index==2){
                this.listgoodArrange.sort((a,b)=>{
                    return b.yx-a.yx;
                })
            }
        },
    }
}
</script>

<style lang="scss" scoped>
    .list{
        margin: 10px;
    }
   .list .title{
    width: 100%;
    height: 20px;
    padding-left: 10px;
    font-weight: bold;
   }
    // 综合排序按钮
    .list .list_btn{
        width: 100%;
        height: 30px;
        display: flex;
        justify-content: space-between;
        margin: 10px 0;
        box-sizing: border-box;
        font-size: 14px;
    }
    .list .list_btn div{
        width: 20%;
        height: 30px;
        line-height: 30px;
        text-align: center;
        border-radius: 5px;
    }
    // 按钮定义一个类让，点击时高亮
    .btnAcivt{
        font-weight: bold;
    }
    // 综合排序下面的列表
    .list .list_content{
        width: 100%;
        height: 30px;
        display: flex;
        justify-content: space-between;
        margin: 15px 0;
        box-sizing: border-box;

    }
    .list .list_content div{
        width: 20%;
        height: 30px;
        line-height: 30px;
        text-align: center;
        border-radius: 5px;
        background: #f5f5f5;
        font-size: 12px;
    }
    // 商品信息列表
    .list_good{
        margin: 10px;
        width: 100%;
        display: flex;
    }
    .list_good .good_img{
        width: 60px;
        height: 60px;
        border: 1px solid #000;
    }
    .list_good .good_img img{
        width: 100%;
    }
    .good_message{
        margin-left: 10px;
    }
    .good_message .good{
        line-height: 20px;
    }
    .good_message .good_name{
        font-weight: bold;
    }
    .good_message span{
        font-size: 12px;
    }
    .good_message .manjian{
        display: flex;
        width: 100%;
        height: 20px;
        margin: 10px 0;
    }
    .good_message .manjian div{
        height: 20px;
        border: 1px solid red;
        margin-right :10px;;
        font-size: 12px;
        line-height: 20px;
        color: red;
    }
</style>